#include "headfiles.h"

using namespace std;

int rand7() {
    while (true) {
        int n = 5 * (rand() % 5) + (rand() % 5);
        if (n < 21) {
            return (n % 7 + 1);
        }
    }

    return 0;
}

int rand7_orig() {
    return rand() % 7 + 1;
}

int main(int argc, char **argv) {
    if (argc != 2) {
        cout << "Usage: " << argv[0] << " num" << endl;
        return 0;
    }

    int num = atoi(argv[1]);
    if (num <= 0) {
        cout << "Invalid input argument!" << endl;
        return 1;
    }

    srand(time(NULL));

    int array[8], array_orig[8];
    memset(array, 0, sizeof(int) * 8);
    memset(array_orig, 0, sizeof(int) * 8);

    int i;
    for (i = 0; i < num; i++) {
        int rn = rand7();
        ++array[rn];
    }
    
    for (i = 0; i < num; i++) {
        int rn = rand7_orig();
        ++array_orig[rn];
    }

    cout << "Probabilites: " << endl;
    for (i = 1; i <= 7; i++) {
        cout << "P(" << i << ") = " << 1.0 * array[i] / num << endl;
    }

    cout << "Probabilites of orig: " << endl;
    for (i = 1; i <= 7; i++) {
        cout << "P(" << i << ") = " << 1.0 * array_orig[i] / num << endl;
    }

    return 0;
}

